<?php
namespace app\home\model;

use think\Model;

class UserModel extends Model
{
    protected $table = 'sf_user';
    public function add_user($mobile){
        $data = [];
        $data['mobile'] = $mobile;
        $data['salt'] = rand('1000','9999');
        $data['password'] = md5($this->str_rand(32).$data['salt']);
        return $this->insert($data);
    }
   private function str_rand($length = 32, $char = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
        if(!is_int($length) || $length < 0) {
            return false;
        }

        $string = '';
        for($i = $length; $i > 0; $i--) {
            $string .= $char[mt_rand(0, strlen($char) - 1)];
        }

        return $string;
    }
}
